from math import log


def solution(V, W):
    # Edit your code here
    flag = W - V
    if flag < 0:
        if V - pow(V, 0) == W:
            return "Yes"
        elif V - 2 * pow(V, 0) == W:
            return "Yes"
        else:
            return "NO"
    if flag == 0:
        return "Yes"
    if flag > 0:
        index = int(log(W, V))
        W -= pow(V, index)
        flag = W - V
        if flag > 0:
            W -= pow(V, index)
            flag = W - V
            if flag > 0:
                return "NO"
            else:
                if V - pow(V, 0) == W:
                    return "Yes"
                elif V - 2 * pow(V, 0) == W:
                    return "Yes"
                else:
                    return "NO"
        if flag < 0:
            if V - pow(V, 0) == W:
                return "Yes"
            elif V - 2 * pow(V, 0) == W:
                return "Yes"
            else:
                return "NO"


if __name__ == "__main__":
    # Add your test cases here
    print(solution(10, 9) == "Yes")
    print(solution(200, 40199) == "Yes")
    print(solution(108, 50) == "NO")
